<template>
  <div class='voucher first-box'>
    <Tab :tabData="tabData" :selectIndex="selectIndex" :changeFun="changeSelect"></Tab>
    <GreyLine></GreyLine>
    <Scroll :hasmore="hasmore" :pullup="pullup" setHeight="-70">
      <List :data="listData"></List>
    </Scroll>
  </div>
</template>
<script>
import Tab from '../../homepage/regiment/common/tab'
import GreyLine from '../../common/line.vue'
import Scroll from '../../common/scroller'
import List from './common/list'
export default {
  components: {Tab,GreyLine,Scroll,List},
  name: "",
  data() {
    return {
      tabData:[
        {
          label:"未使用",
          type:0,
        },{
          label:"已使用",
          type:1,
        },{
          label:"已过期",
          type:2,
        },
      ],
      selectIndex:0,
      hasmore:false,
      pageInfo:{
        page:1
      },

      listData:[
        // {
        //   id:1,
        //   title:"免费洗车",
        //   money:38,//
        //   time:"2018-12-12",
        //   over:"5",//超出多少可以使用
        //   state:0,//0未使用,1已使用，-1过期
        // },{
        //   id:1,
        //   title:"免费洗车",
        //   money:38,//
        //   time:"2018-12-12",
        //   over:"5",//超出多少可以使用
        //   state:0,//0未使用,1已使用，-1过期
        // }
      ]
    };
  },
  methods: {
    changeSelect(index){
      this.selectIndex=index
      this.listData=[]
      this.getList()
      bus.$emit("resetScroller")
    },

    // 下拉刷新方法回调
    pullup(func){
      if(this.hasmore){
        this.pageInfo.page++
         _g.orderList([this.getList,func])
         return
      }
    },

    getList(){
      var params={
        currPageNo:this.pageInfo.page,
        status:this.selectIndex,
      }
      _g.apiPost("couponApp/getUserCoupon.do",params).then(res=>{
        this.hasmore=res.data.hasNextPage
        
        var goal=[]
        res.data.list.forEach(ele => {
          goal.push({
            id:ele.id,
            title:ele.couponName,
            money:ele.couponValue,
            time:ele.validTill.slice(0,10),
            over:ele.consumptionFull,
            state:ele.status
          })
        });
        this.$set(this,"listData",this.listData.concat(goal))
      })
    }
  },
  created() {
    this.getList()
  }
};
</script>
<style lang="scss" scoped>
.voucher {
  padding-top: 0.1px;
}
</style>